
Page({

  /**
   * 页面的初始数据
   */
  data: {

    checked: false,
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../../images/my/normal.png',
    selectedSrc: '../../../images/my/selected.png',
    halfSrc: '../../../images/my/half.png',
    key: 0, //评分
    img_arr: [],  //存放上传的图片
    formdata: '',
    niming: false,


    score: 0,//评分分数
  },

  // 匿名评价
  radioChange: function (e) {
    var checked1 = this.data.checked;
    var niming1 = this.data.niming;
    this.setData({
      checked: !checked1,
      niming: !niming1
    })
    console.log(this.data.checked)
    console.log(this.data.niming)
  },


  //点击右边,半颗星
  selectLeft: function (e) {
    var score = e.currentTarget.dataset.score
    if (this.data.score == 0.5 && score == 0.5) {
      score = 0;
    }
    console.log("点击左半边,得" + score + "分")
    this.setData({
      score: score
    })
  },
  //点击左边,整颗星
  selectRight: function (e) {
    var score = e.currentTarget.dataset.score
    console.log("点击右半边,得" + score + "分")
    this.setData({
      score: score
    })
  },

  // 获得文本框输入的值
  text: function (e) {
    console.log(e.detail.value)
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 图片上传
  upimg: function () {
    var that = this;
    if (this.data.img_arr.length < 9) {
      wx.chooseImage({
        sizeType: ['original', 'compressed'],
        success: function (res) {
          that.setData({
            img_arr: that.data.img_arr.concat(res.tempFilePaths)
          })
        }
      })
    } else {
      wx.showToast({
        title: '最多上传九张图片',
        icon: 'none',
        duration: 1000
      });
    }
  },
  // 提交评价
  submit: function (e) {
    // var id = e.target.id;
    // var adds = e.detail.value;

    // adds.program_id = app.jtappid
    // adds.openid = app._openid
    // adds.zx_info_id = this.data.zx_info_id
    this.upload()

  },

  upload: function () {
    var that = this
    for (var i = 0; i < this.data.img_arr.length; i++) {
      wx.uploadFile({
        url: '',
        filePath: that.data.img_arr[i],
        name: 'content',
        formData: adds,
        success: function (res) {
          console.log(res)
          if (res) {
            wx.showToast({
              title: '已提交发布！',
              duration: 3000
            });
          }
        }
      })
    }
    this.setData({
      formdata: ''
    })
  },
  // 图片删除
  deleteImage: function (e) {
    let self = this;
    let images = self.data.img_arr;
    let index = e.currentTarget.dataset.index;
    images.splice(index, 1);
    this.setData({
      img_arr: images,
    });
  },

})